package cn.tj.student.dao.impl;

import cn.tj.student.dao.StudentDao;
import cn.tj.student.pojo.Student;
import cn.tj.student.util.MybatiesUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class StudentDaoImpl implements StudentDao {
    @Override
    public List<Student> queryAllStudent() {
        SqlSession sqlSession = MybatiesUtil.getSqlSession();
        List<Student> studentlist = sqlSession.selectList("cn.tj.student.mapper.StudentMapper.queryAllStudent");
        sqlSession.close();
        return studentlist;
    }

    @Override
    public int addStudent(Student student) {
        SqlSession sqlSession = MybatiesUtil.getSqlSession();
        int row= sqlSession.insert("cn.tj.student.mapper.StudentMapper.addStudent",student);
        return row;
    }

    @Override
    public Student queryOne(Long id) {
        SqlSession sqlSession = MybatiesUtil.getSqlSession();
        Student student = sqlSession.selectOne("cn.tj.student.mapper.StudentMapper.queryOne",id);
        return student;
    }

    @Override
    public int updateStudent(Student student) {
        SqlSession sqlSession = MybatiesUtil.getSqlSession();
        int row = sqlSession.update("cn.tj.student.mapper.StudentMapper.updateStudent", student);
        return row;
    }

    @Override
    public int deleteStudent(Long id) {
        SqlSession sqlSession = MybatiesUtil.getSqlSession();
        int row = sqlSession.delete("cn.tj.student.mapper.StudentMapper.deleteStudent",id);
        return row;
    }
}
